package com.mx.kn.cstf2.service.impl;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import kn.cstf2.transition.Bean.TransitionBean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mx.kn.cstf2.dao.ForoDao;
import com.mx.kn.cstf2.dto.ComentarioDto;
import com.mx.kn.cstf2.dto.ForoDto;
import com.mx.kn.cstf2.service.ForoService;



@Service
public class ForoServiceImpl implements ForoService {

	@Autowired ForoDao foroDao;
	
	@Override
	public List<ForoDto> getTopics(TransitionBean transition) throws SQLException {
		return foroDao.getTopics(transition);
	}

	@Override
	public List<ComentarioDto> getListComentarios(int idTopico, int idForo)
			throws SQLException {
		return foroDao.getListComentarios(idTopico, idForo);
	}

	@Override
	public void insertComment(int idTopico, int idComentarioPadre,int idForo, String comentario, String autor)throws SQLException{	
		foroDao.insertComment(idTopico, idComentarioPadre, idForo, comentario, autor);
		ForoDto foro = new ForoDto();
		foro.setId_topico(idTopico);
		foro.setIdForo(idForo);
		foroDao.insertLastUpdateForo(new Date(), autor, foro);
	}

	@Override
	public void updateUrlImgComment(int idTopico, int idComentario, int idForo,
			String urlImg, String user) throws SQLException {
		foroDao.updateUrlImgComment(idTopico, idComentario,idForo, urlImg);	
		ForoDto foro = new ForoDto();
		foro.setId_topico(idTopico);
		foro.setIdForo(idForo);
		foroDao.insertLastUpdateForo(new Date(), user, foro);
	}

	@Override
	public void updateUrlFileComment(int idTopico, int idComentario, int idForo,
			String urlFile, String user) throws SQLException {
		foroDao.updateUrlFileComment(idTopico, idComentario, idForo, urlFile);
		ForoDto foro = new ForoDto();
		foro.setId_topico(idTopico);
		foro.setIdForo(idForo);
		foroDao.insertLastUpdateForo(new Date(), user, foro);
		
	}

	@Override
	public ComentarioDto getComentartio(int idTopico, int idComentario,
			TransitionBean transition) throws SQLException {
		// TODO Auto-generated method stub
		return foroDao.getComentartio(idTopico, idComentario, transition);
	}
	
	

}
